﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoGenTool.Helpers
{
    public static class StringHelper
    {
        ///<summary>将字符串变成类似 StudentName 这样的大写开头的格式</summary>
        public static string ToPascal(string name)
        {
            name = TrimUnderlineAndSpace(name);
            var firstChar = name[0];
            firstChar = char.ToUpper(firstChar);
            return $"{firstChar}{name.Substring(1)}";
        }

        ///<summary>将字符串变成类似 studentName 这样的下划线开头小写的格式</summary>
        private static string ToCamel(string name)
        {
            name = TrimUnderlineAndSpace(name);
            var firstChar = name[0];
            firstChar = char.ToLower(firstChar);
            return $"_{firstChar}{name.Substring(1)}";
        }

        ///<summary>将字符串变成类似 _studentName 这样的下划线开头小写的格式</summary>
        public static string ToUnderlineCamel(string name)
        {
            return $"_{ToCamel(name)}";
        }

        private static string TrimUnderlineAndSpace(string name)
        {
            name = name.Trim('_').Trim(' ');
            return name;
        }

    }
}
